package com.aiyige.page.publish.coursedescription.adapter;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.page.publish.coursedescription.model.CourseCover;
import com.aiyige.utils.widget.RoundCornerImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhuyakun on 2017/12/13.
 */

public class CourseCoverAdapter extends BaseQuickAdapter<CourseCover, CourseCoverAdapter.ViewHolder> {


    public CourseCoverAdapter() {
        super(R.layout.course_cover, new LinkedList<CourseCover>());
    }

    @Override
    protected void convert(ViewHolder helper, CourseCover item) {
        helper.bindData(item);
    }


    public class ViewHolder extends BaseViewHolder {
        @BindView(R.id.addTv)
        TextView addTv;
        @BindView(R.id.coverTv)
        TextView coverTv;
        @BindView(R.id.editTv)
        TextView editTv;
        @BindView(R.id.coverLayout)
        FrameLayout coverLayout;
        @BindView(R.id.coverIv)
        RoundCornerImageView coverIv;
        @BindView(R.id.videoPlayIv)
        ImageView videoPlayIv;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

        public void bindData(CourseCover item) {
            switch (item.getType()) {
                case CourseCover.TYPE_ADD:
                    coverLayout.setVisibility(View.INVISIBLE);
                    break;
                case CourseCover.TYPE_NORMAL:
                    coverLayout.setVisibility(View.VISIBLE);
                    Glide.with(itemView.getContext())
                            .load(item.getImageUrl())
                            .apply(RequestOptions.placeholderOf(android.R.color.white))
                            .into(coverIv);
                    coverTv.setVisibility(item.isDefaultCover() ? View.VISIBLE : View.INVISIBLE);
                    switch (item.getMediaType()) {
                        case CourseCover.MEDIA_TYPE_PHOTO:
                            videoPlayIv.setVisibility(View.INVISIBLE);
                            break;
                        case CourseCover.MEDIA_TYPE_VIDEO:
                            videoPlayIv.setVisibility(View.VISIBLE);
                            break;
                    }
                    break;
            }
        }
    }
}
